﻿using Cordyceps.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Cordyceps.Demo.EntityFrameworkCore.EFCore;

public class DemoDbContext : CordycepsDbContextBase<DemoDbContext>
{
    /// <summary>
    ///     关键：这个构造函数允许从外部传入配置（如连接字符串）
    /// </summary>
    /// <param name="options"></param>
    public DemoDbContext(DbContextOptions<DemoDbContext> options) : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ConfigureDemo();
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
#if DEBUG
        optionsBuilder.EnableSensitiveDataLogging();
#endif
        base.OnConfiguring(optionsBuilder);
    }
}